package com.travelsupport.common;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.travelsupport.myobject.LocationObj;
import com.travelsupport.ui.R;

public class MyFavoriteListViewAdapter extends BaseAdapter {

	LayoutInflater inflater;
	List<LocationObj> items;

	public MyFavoriteListViewAdapter(Activity context, List<LocationObj> items) {
		super();

		this.items = items;
		this.inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		LocationObj favoriteLocation = items.get(position);

		View vi = convertView;

		if (convertView == null)
			vi = inflater.inflate(R.layout.my_favorite_row, null);

		ImageView imgFavorive = (ImageView) vi
				.findViewById(R.id.imgFavoriteIcon);
		TextView txtFavoritePlaceName = (TextView) vi
				.findViewById(R.id.txtFavoritePlaceName);
		CheckBox cbFavoriteItem = (CheckBox) vi
				.findViewById(R.id.cbFavoriteItem);

		imgFavorive.setImageBitmap(new Common()
				.convertToPictureId(favoriteLocation.getImage()));
		txtFavoritePlaceName.setText(favoriteLocation.getName());
		cbFavoriteItem.setChecked(favoriteLocation.getRemoveCheckBox());

		return vi;
	}

}